﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.Collections;
using ECCIT;
using ECCIT.Web;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using OgilvyOne.UKNow.Globalization;
using System.IO;

public partial class admin_UKNOW_SyncEvents : System.Web.UI.Page
{
    private const string VIEWSTATE_COLUMN_ID = "columnid";
    private const string VIEWSTATE_LAYER_ID = "layerid";
    int sid = 2052;
    string sname = "";
    int tid = 2052;
    string tname = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ViewState[VIEWSTATE_COLUMN_ID] = int.Parse(Request.Params[VIEWSTATE_COLUMN_ID]);
            ViewState[VIEWSTATE_LAYER_ID] = Request.Params[VIEWSTATE_LAYER_ID];
            btnSync.Attributes["onclick"] = "javascript:return checkForm();";
        }
    }
    protected void SourceEventLangID_SelectedIndexChanged(object sender, EventArgs e)
    {
        sid = Convert.ToInt32(SourceEventLangID.SelectedValue);
        List<EventsModel> Eventlist = new EventsBLL(sid).seleventsByName(sid);
        this.SourceEventName.Items.Clear();
        this.SourceEventName.Items.Add(new ListItem("--请选择活动名称--", ""));
        foreach (EventsModel events in Eventlist)
        {
            this.SourceEventName.Items.Add(new ListItem(events.Title, events.Title.ToString()));
        }
    }
    protected void SourceEventName_SelectedIndexChanged(object sender, EventArgs e)
    {
        sname = SourceEventName.SelectedValue;
        if (SourceEventLangID.SelectedValue != string.Empty)
        {
            if (int.Parse(SourceEventLangID.SelectedValue) == (int)LanguageType.cn)
                sname = sname.Replace("•", "_").Replace("·", "_");
            else
                sname = sname.Replace("'", "_");
        }
        sid = Convert.ToInt32(SourceEventLangID.SelectedValue);
        IList<EventsModel> Eventlist = new EventsBLL(sid).selEveByNandL(sid, sname);
        this.SourceEventID.Items.Clear();
        foreach (EventsModel events in Eventlist)
        {
            this.SourceEventID.Items.Add(new ListItem(events.ID.ToString(), events.ID.ToString()));
        }
    }
    protected void ToEventLangID_SelectedIndexChanged(object sender, EventArgs e)
    {
        tid = Convert.ToInt32(ToEventLangID.SelectedValue);
        List<EventsModel> Eventlist = new EventsBLL(tid).seleventsByName(tid);
        this.ToEventName.Items.Clear();
        this.SourceEventName.Items.Add(new ListItem("--请选择活动名称--", ""));
        foreach (EventsModel events in Eventlist)
        {
            this.ToEventName.Items.Add(new ListItem(events.Title, events.Title));
        }
    }
    protected void ToEventName_SelectedIndexChanged(object sender, EventArgs e)
    {
        tid = Convert.ToInt32(ToEventLangID.SelectedValue);
        tname = ToEventName.SelectedValue;
        if (ToEventLangID.SelectedValue != string.Empty)
        {
            if (int.Parse(ToEventLangID.SelectedValue) == (int)LanguageType.cn)
                tname = tname.Replace("•", "_").Replace("·", "_");
            else
                tname = tname.Replace("'", "_");
        }
        IList<EventsModel> Eventlist = new EventsBLL(tid).selEveByNandL(tid, tname);
        this.ToEventID.Items.Clear();
        foreach (EventsModel events in Eventlist)
        {
            this.ToEventID.Items.Add(new ListItem(events.ID.ToString(), events.ID.ToString()));
        }
    }
    protected void btnSync_click(object sender, EventArgs e)
    {
        try
        {
            sid = Convert.ToInt32(SourceEventLangID.SelectedValue);
            string seid = SourceEventID.SelectedValue;
            EventsModel srcModel = new EventsModel();
            srcModel.LanguageID = sid;
            srcModel.ID = int.Parse(seid);

            tid = Convert.ToInt32(ToEventLangID.SelectedValue);
            string teid = ToEventID.SelectedValue;
            EventsModel destModel = new EventsModel();
            destModel.LanguageID = tid;
            destModel.ID = int.Parse(teid);

            EventsBLL bll = new EventsBLL(sid);
            bll.SyncEventsAttachments(srcModel, destModel);

            Response.Write("<script>alert('图片同步成功');</script>");
        }
        catch (Exception ex)
        {
            Response.Write(string.Format("<script>alert('图片同步失败，错误信息：{0}' );</script>", ex.Message));
        }
    }
}